import { api } from '../commission.service';
import { useModal } from '@/sheep/hooks';
import AgentDetail from './detail.vue';

export function useHandle(fn) {
  const statusList = {
    normal: { label: '正常', color: '#52c41a' },
    pending: { label: '审核中', color: '#faad14' },
    reject: { label: '拒绝', color: '#f56c6c' },
    freeze: { label: '冻结', color: '#409eff' },
    forbidden: { label: '禁用', color: '#999999' },
  };

  async function onEdit(id, params) {
    const { data } = await api.agent.edit(id, params);
    fn();
  }

  function onDetail(id) {
    useModal(
      AgentDetail,
      {
        title: '分销商详情',
        id,
      },
      {
        confirm: () => {
          fn();
        },
      },
    );
  }

  async function onDelete(id) {
    const { data } = await api.agent.delete(id);
    fn();
  }

  return {
    statusList,
    onEdit,
    onDetail,
    onDelete,
  };
}
